package com.ruoyi.web.controller.caipiao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.caipiao.dto.req.GeneratePl5Req;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.caipiao.domain.CaipiaoPl5;
import com.ruoyi.caipiao.service.ICaipiaoPl5Service;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排列5计算Controller
 *
 * @author ruoyi
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/caipiao/calpl5")
public class CaipiaoPl5Controller extends BaseController {
    @Autowired
    private ICaipiaoPl5Service caipiaoPl5Service;

    @GetMapping("getKjNum/{qs}")
    public AjaxResult getKjNum(@PathVariable("qs") String qs) {
        return success().put("data", caipiaoPl5Service.getKjNum(qs));
    }

    /**
     * 生成号码
     *
     * @param generatePl5Req
     * @return
     */
    @PostMapping("/savePl3Num")
    public AjaxResult savePl3Num(@RequestBody GeneratePl5Req generatePl5Req) {
        caipiaoPl5Service.addPl5Num(generatePl5Req);
        return success();
    }
    /**
     * 生成号码
     *
     * @param generatePl5Req
     * @return
     */
    @PostMapping("/generateNum")
    public AjaxResult generateNum(@RequestBody GeneratePl5Req generatePl5Req) {
        String r = "";
        if (generatePl5Req.getMethod() == 1) {
            r = caipiaoPl5Service.generateNumMethod1(generatePl5Req);
        } else if (generatePl5Req.getMethod() == 2) {
            r = caipiaoPl5Service.generateNumMethod2(generatePl5Req);
        } else if (generatePl5Req.getMethod() == 3) {
            r = caipiaoPl5Service.generateNumMethod3(generatePl5Req);
        } else if (generatePl5Req.getMethod() == 4) {
            r = caipiaoPl5Service.generateNumMethod4(generatePl5Req);
        } else if (generatePl5Req.getMethod() == 5) {
            r = caipiaoPl5Service.generateNumMethod5(generatePl5Req);
        } else if (generatePl5Req.getMethod() == 6) {
            r = caipiaoPl5Service.generateNumMethod6(generatePl5Req);
        }
            return success().put(AjaxResult.DATA_TAG, r);
    }


    /**
     * 查询排列5计算列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:pl5:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaipiaoPl5 caipiaoPl5) {
        startPage();
        List<CaipiaoPl5> list = caipiaoPl5Service.selectCaipiaoPl5List(caipiaoPl5);
        return getDataTable(list);
    }

    /**
     * 导出排列5计算列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:pl5:export')")
    @Log(title = "排列5计算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaipiaoPl5 caipiaoPl5) {
        List<CaipiaoPl5> list = caipiaoPl5Service.selectCaipiaoPl5List(caipiaoPl5);
        ExcelUtil<CaipiaoPl5> util = new ExcelUtil<CaipiaoPl5>(CaipiaoPl5.class);
        util.exportExcel(response, list, "排列5计算数据");
    }

    /**
     * 获取排列5计算详细信息
     */
    @PreAuthorize("@ss.hasPermi('caipiao:pl5:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(caipiaoPl5Service.selectCaipiaoPl5ById(id));
    }

    /**
     * 新增排列5计算
     */
    @PreAuthorize("@ss.hasPermi('caipiao:pl5:add')")
    @Log(title = "排列5计算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaipiaoPl5 caipiaoPl5) {
        return toAjax(caipiaoPl5Service.insertCaipiaoPl5(caipiaoPl5));
    }

    /**
     * 修改排列5计算
     */
    @PreAuthorize("@ss.hasPermi('caipiao:pl5:edit')")
    @Log(title = "排列5计算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaipiaoPl5 caipiaoPl5) {
        return toAjax(caipiaoPl5Service.updateCaipiaoPl5(caipiaoPl5));
    }

    /**
     * 删除排列5计算
     */
    @PreAuthorize("@ss.hasPermi('caipiao:pl5:remove')")
    @Log(title = "排列5计算", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(caipiaoPl5Service.deleteCaipiaoPl5ByIds(ids));
    }
}
